package com.yang.service.impl;

import com.yang.dao.ClassifyMapper;
import com.yang.dao.EssayMapper;
import com.yang.dao.LableMapper;
import com.yang.entity.Classify;
import com.yang.entity.Essay;
import com.yang.service.EssayService;
import com.yang.utils.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2019/7/3.
 */
@Service
public class EssayServiceImpl  implements EssayService {
    //引入文章的dao
     @Autowired
     private EssayMapper essayMapper;
     //引入标签
     @Autowired
     private LableMapper lableMapper;
     //引入文章分类的标签
      @Autowired
      private ClassifyMapper classifyMapper;

    /**
     *增加文章
     * @param essay
     */
    @Override
    public void addEssay(Essay essay) {
         essay.setEstate(Essay.ESSAY_STATE_SEND);
         essayMapper.insert(essay);
    }

    /**
     * 更新状态
     * @param essay
     */
    @Override
    public void updateEssay(Essay essay) {
        essayMapper.updateByPrimaryKey(essay);
    }

    @Override
    public void deleteEssay(Integer essayId) {
          essayMapper.deleteByPrimaryKey(essayId);
    }

    @Override
    public void roughEssay(Essay essay) {
        essay.setEstate(Essay.ESSAY_STATE_ROUGH);
        essayMapper.insert(essay);
    }

    @Override
    public void updateEssayState(Integer essayId, String state) {
        Essay essay=new Essay();
        essay.setEstate(state);
        essay.setEid(essayId);
        essayMapper.updateByPrimaryKey(essay);
    }



    @Override
    public Classify findClassifyByEssayId(Integer essayId) {
        /**
         * 先根据ID查询
         */
        Essay essay=essayMapper.selectByPrimaryKey(essayId);
        //然后根据文章的ID查询出是哪类
        return classifyMapper.selectByPrimaryKey(essay.getEid());
    }

    //统计该分类下所有文章总数
    @Override
    public int countEssayByClassifyId(Integer classifyId) {
        return 0;
    }

    @Override
    public List<Essay> findEssaysByClassifyId(String classifyId) {
        return null;
    }

    @Override
    public List<Essay> findEssaysByLabelId(String labelId) {
        return null;
    }

    @Override
    public Essay findEssayById(Integer essayId) {
        return null;
    }

    @Override
    public void addViewSize(Integer essayId) {

    }

    @Override
    public List<Essay> findEssays() {
        return null;
    }

    @Override
    public PageResult findPaginationAll(int thisPage, int pageSize) {
        return null;
    }

    @Override
    public List<Essay> findTopNew() {
        return null;
    }

    @Override
    public List<Essay> findTopView() {
        return null;
    }

    @Override
    public void updatePageView(Integer essayId) {

    }

    @Override
    public PageResult searchEssay(String keyword, int thisPage) {
        return null;
    }
}
